package eu.webmedia.recruitment.comics.strips;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import eu.webmedia.recruitment.comics.preferences.PreferenceService;
import eu.webmedia.recruitment.comics.preferences.Preferences;
import eu.webmedia.recruitment.comics.user.User;
import eu.webmedia.recruitment.comics.user.UserUtil;

@Controller
public class StripsController {
	
	@Resource
	private CyanideAndHappinessStripUrlFinder cyanideAndHappinessStripUrlFinder;
	
	@Resource
	private WulffmorgenthalerStripUrlFinder wulffmorgenthalerStripUrlFinder;
	
	@Resource
	private XkcdStripUrlFinder xkcdStripUrlFinder;
	
	@Resource
	private PreferenceService preferenceService;
	
	
	@RequestMapping(value = "/strips.do", method=RequestMethod.GET)
	public String strips(Model model) {
		User currentUser = UserUtil.getCurrentUser();
		
		Preferences preferences = preferenceService.findByUser(currentUser);
		
		List<String> strips = new ArrayList<String>();
		
		if (preferences.contains("xkcd")) {
			strips.add(xkcdStripUrlFinder.findUrl());
		}
		if (preferences.contains("Cyanide & Happiness")) {
			strips.add(cyanideAndHappinessStripUrlFinder.findUrl());
		}
		
		if (preferences.contains("Wulffmorgenthaler")) {
			strips.add(wulffmorgenthalerStripUrlFinder.findUrl());
		}
		
		model.addAttribute("strips", strips);

		return "strips";
	}
	
}
